/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Operacoes_DataBase;

import DataBase.Conexao;
import Main.classe.Funcionario;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
//import java.util.ArrayList;

/**
 *
 * @author raphael
 */
public class gravacoes {
    
    private Connection connect;
    
    public void insertFun(Funcionario fun) throws SQLException{
        connect = new Conexao().getConnection();
        String sql = "INSERT INTO Funcionario"
                + " (cd_funcionario, ds_bairro, cd_cargo, ds_cidade, "
                + "ds_email, ds_endereco, ds_foto, ds_telefone, nm_funcionario)"
                + "VALUES(?,?,?,?,?,?,?,?,?); ";
        System.out.println(sql);
        try{
            //prepara o statement para inserção no banco.
            PreparedStatement stmt = this.connect.prepareStatement(sql);
            //definir os valores de acordo com o passado pelo objeto
            stmt.setInt(1, fun.getCodigo());
            stmt.setString(2, fun.getBairro());
            stmt.setInt(3, fun.getCargo());
            stmt.setString(4, fun.getCidade());
            stmt.setString(5, fun.getEmail());
            stmt.setString(6, fun.getEndereco());
            stmt.setString(7, fun.getFoto());
            stmt.setString(8, fun.getTelefone());
            stmt.setString(9, fun.getNome());
            
            //executa o statement
            stmt.execute();
            stmt.close();
            
        }catch{(SQLException e) {
            throw new RuntimeException(e);
        } finally {
            this.connect.close();
        }
        System.out.println(sql);
   
    
    }
}
